<template>
	<view class="reg-page">
		<view class="input-row top-bottom space-between" @click="uploadImgs">
			<view class="head-img">
				<image :src="$mConfig.imageUrl + '/image/icon-head.png'"></image>
			</view>
			<view class="header">
				<text class="title">设置logo</text>
				<text class="yzb yzb-next"></text>
				<!-- <text class="tip">上传真实头像，回复率翻倍哦！</text> -->
			</view>
		</view>
		<view class="input-group">
			<view class="input-column border-bottom-1px" @click="changeFun(item,index)" v-for="(item,index) in list"
				:key="index">
				<view class="title">
					<image class="icon" :src="item.icon"></image>
					{{item.name}}
				</view>
				<view class="" v-if="index==2">{{itemValue}}</view>
				<view class="input-item">
					<text class="yzb yzb-next"></text>
				</view>
			</view>
		</view>
		<view class="input-group">
			<view class="input-column border-bottom-1px" @click="changeFun2(item,index)" v-for="(item,index) in list1"
				:key="index">
				<view class="title">
					<image class="icon" :src="item.icon"></image>
					{{item.name}}
				</view>
				<view class="" v-if="index==0">{{financingValue}}</view>

				<view class="input-item">
					<text class="yzb yzb-next"></text>
				</view>
			</view>
		</view>
		<u-picker :show="show" :columns="columns" @confirm="confirm" @cancel="cancel"></u-picker>
		<u-picker :show="financingShow" :columns="financingList" @confirm="financingConfirm"
			@cancel="financingCancel"></u-picker>

	</view>
</template>

<script>
	export default {
		data() {
			const currentDate = this.getDate({
				format: true,
			})
			const start = this.getDate('start')
			return {
				itemValue: '',
				financingValue: '',
				show: false,
				columns: [
					['0~20', '20~50', '50~100', '100~999']
				],
				financingShow: false,
				financingList: [['不需要融资', '种子轮', '天使轮']],
				date: currentDate,
				array: ['高中以下', '高中', '中专/技校', '大专', '本科', '硕士', '博士'],
				tmpImageUrl: '',
				resumeInfo: {
					avatar: '',
					birthday: start,
					timeToWork: currentDate,
					name: '',
					sex: 1,
					education: null,
					phone: '',
					email: '',
					status: 0,
				},
				list: [{
						name: '公司类型',
						icon: this.$mConfig.imageUrl + '/image/my/gongsileixing.png',
						url: '/pages/user/company/companyType'
					},
					{
						name: '上班时间',
						icon: this.$mConfig.imageUrl + '/image/my/shijian.png',
						url: '/pages/user/company/workTime'
					},
					{
						name: '公司规模',
						icon: this.$mConfig.imageUrl + '/image/my/gongsiguimo.png',
						url: '/pages/user/company/company'
					}
				],
				list1: [{
						name: '融资类型',
						icon: this.$mConfig.imageUrl + '/image/my/rongzidaikuan.png',
						url: ''
					},
					{
						name: '公司福利',
						icon: this.$mConfig.imageUrl + '/image/my/fuli.png',
						url: '/pages/user/company/companyBenefits'
					},
					{
						name: '公司办公地址',
						icon: this.$mConfig.imageUrl + '/image/my/address.png',
						url: ''
					},
					{
						name: '公司介绍',
						icon: this.$mConfig.imageUrl + '/image/my/jieshao.png',
						url: ''
					},
					{
						name: '公司相册',
						icon: this.$mConfig.imageUrl + '/image/my/xiangce.png',
						url: ''
					},
					{
						name: '薪资设置',
						icon: this.$mConfig.imageUrl + '/image/my/qianbao.png',
						url: ''
					}
				]
			}
		},
		onLoad() {
			if(this.userInfo && this.userInfo.avatar){
				this.resumeInfo.avatar = this.userInfo.avatar
				this.resumeInfo.phone = this.userInfo.mobile
				this.getResumeInfo()
			}
			
		},
		methods: {
			//融资
			financingConfirm(e) {
				this.financingValue = e.value[0]
				this.financingShow = false
			},
			financingCancel() {
				this.financingShow = false
			},
			confirm(e) {
				this.itemValue = e.value[0]
				this.show = false
			},
			cancel() {
				this.show = false
			},
			getResumeInfo() {
				getUserInfo().then(res => {
					console.log(res.data, 'res.data')
					this.resumeInfo = res.data
				})
			},
			changeFun2(item, index) {
				if (index == 0) {
					this.financingShow = true
				} else {
					uni.navigateTo({
						url: item.url
					})
				}
			},
			changeFun(item, index) {
				console.log(index, 'index')
				if (index == 2) {
					this.show = true
				} else {
					uni.navigateTo({
						url: item.url
					})
				}
				// let url=''
				// if (type == 1) {
				//   url = '/pages/user/person/user-message/changName?realName='+this.resumeInfo.realName
				// } else if (type == 2) {
				//   url = '/pages/user/person/edit-address'
				// } else if (type == 3) {
				//   url = '/pages/user/person/user-message/changWoker?workDate='+this.resumeInfo.workDate
				// } else if (type == 4) {
				//   url = '/pages/user/person/user-message/changWechat?wechatCode='+this.resumeInfo.wechatCode
				// } else if (type == 5) {
				//   url = '/pages/user/person/user-message/changBirth?birthday='+this.resumeInfo.birthday
				// }

			},
			bindPickerChange: function(e) {
				this.resumeInfo.education = this.array[e.target.value]
			},

			bindBirthdayChange: function(e) {
				this.resumeInfo.birthday = e.target.value
			},

			bindDateChange: function(e) {
				this.resumeInfo.timeToWork = e.target.value
			},

			radioChange(val) {
				this.resumeInfo.sex = val.detail.value
				console.log('radioChange', val)
			},
			radioChange2(val) {
				this.resumeInfo.status = val.detail.value
				console.log('radioChange2', val)
			},

			// 选择图片
			uploadImgs() {
				uni.navigateTo({
					url: '/pages/user/company/company'
				})
				// let that = this
				// uni.chooseImage({
				//   success(res) {
				//     let tempFilePaths = res.tempFilePaths
				//     that.tmpImageUrl = tempFilePaths[0]
				//     that.uploadFile()
				//   },
				// })
			},

			// 上传图片
			uploadFile() {
				uni.showLoading({
					title: '图片上传中',
				})
				let that = this
				uploadImage(0, this.tmpImageUrl, 'job/user/', (result) => {
					console.log('图片上传结果：', result)
					that.resumeInfo.avatar = result
					uni.hideLoading()
				})
			},

			getDate(type) {
				const date = new Date()
				let year = date.getFullYear()
				let month = date.getMonth() + 1
				let day = date.getDate()

				if (type === 'start') {
					year = year - 60
				} else if (type === 'end') {
					year = year + 2
				}
				month = month > 9 ? month : '0' + month
				day = day > 9 ? day : '0' + day
				return `${year}-${month}-${day}`
			},

			// 更新
			async update() {
				let checkRes = graceChecker.check(this.resumeInfo, formRuleConfig.regResumeBaseRule)
				if (!checkRes) {
					uni.showToast({
						title: graceChecker.error,
						icon: 'none',
					})
					return
				}
				let res = await this.$apis.updateResumeBasic(this.resumeInfo)
				if (res) {
					// this.$mRouter.push({
					// 	route: this.$mRoutesConfig.personReume
					// });
					uni.navigateBack({
						delta: 1,
					})
				}
			}
		},
	}
</script>
<style>
	page {
		background: #F1F4FB;
	}
</style>
<style lang="scss" scoped>
	.reg-page {
		.input-group {
			padding: 10rpx 30rpx 20rpx;
			border-top: 20rpx solid #f1f4fb;
			background: #FFFFFF;
		}

		.padding-10 {
			font-size: 30rpx;
			color: #333;
			padding-left: 60rpx;
			padding-top: 28rpx;
		}

		.top-bottom {
			background: #fff;
			padding: 10rpx 30rpx 20rpx;
		}
	}

	.space-between {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.input-row {
		flex-direction: row;
		position: relative;
		padding: 30rpx 20rpx;
	}

	.border-bottom-1px {
		border-bottom: 1px solid #f9f9f9;
	}

	.header {
		display: flex;
		align-items: center;

		// flex-direction: column;
		.title {
			font-size: 36rpx;
			color: #999999;
			margin-left: 20upx;
		}

		.yzb-next {
			color: #333333;
			font-size: 40rpx;
			margin-left: 10rpx;
			font-weight: bold;
		}
	}

	.head-img {
		margin-right: 15upx;

		image {
			width: 124upx;
			height: 124upx;
			border-radius: 50%;
		}
	}

	radio-group {
		margin-right: 10upx;
	}

	.radio {
		margin-left: 20upx;
	}

	.input-column {
		display: flex;
		padding: 38rpx 0;
		justify-content: space-between;
		align-items: center;

		.input-item {
			// display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
		}

		.picker {
			position: relative;

			picker {
				font-size: $uni-font-size-lg;
				width: 100%;
				// position: absolute;
			}
		}

		.yzb-next {
			float: right;
			color: #222;
			font-size: 42rpx;
		}
	}

	.title {
		color: #222;
		font-size: 32rpx;
		display: flex;
		align-items: center;

		.icon {
			width: 36rpx;
			height: 36rpx;
			margin-right: 24rpx;
		}
	}
</style>